package com.lgd.tools;

import clover.com.lowagie.text.Document;
import clover.com.lowagie.text.PageSize;
import clover.com.lowagie.text.Phrase;
import clover.com.lowagie.text.rtf.RtfWriter2;
import clover.org.apache.commons.lang.math.RandomUtils;

import java.io.FileOutputStream;

public class ToWord {

	// 创建到word文档
	public static void formWordDocument( String[] content) {
		// 创建word文档PageSize.A4,表示用什么型号的纸
		Document document = new Document(PageSize.A4);
		try {
            RtfWriter2.getInstance(document, new FileOutputStream(
					"d:\\FILE\\word\\"+content[RandomUtils.nextInt(content.length)]+".doc"));
			document.open();

			// 设置中文字体大小
			//BaseFont bfChinese = BaseFont.createFont("STSong-Light",
			//		"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			//Font fontChinese = new Font(bfChinese, 12, Font.NORMAL);
            for (int i = 0; i < content.length; i++) {
                document.add(new Phrase(content[RandomUtils.nextInt(content.length)]+" "));
            }

		} catch (Exception e) {
			e.printStackTrace();
		}

		document.close();

	}

	public static void main(String[] args) throws Exception {
		formWordDocument(WordBase.getWords(500));
	}

}
